<?php
/**
 * Created by xuan.
 * Author: xuan
 * Date: 2018/8/4
 * Time: 18:24
 */

namespace app\api\model;
use think\Db;

class Returnorder extends BaseModel
{	
	protected $table = 'returnorder';
	
	public static function selectOneReturnorderByOid($oid){
		$data = model("Returnorder")->where(array("oid"=>$oid))->find();
		return $data;
	}
	
	public static function addOneReturnorder($all)
    {
		$data = Returnorder::create([
			'mid' => $all['mid'],
			'oid' => $all['oid'],
			'orderpic' => $all['orderpic'],
			'productpic' => $all['productpic'],
			'returncause' => $all['returncause'],
			'status' => 2,//1审核通过，2待审核，3审核未通过
			'addtime' => date('Y-m-d H:i:s',time()),
			'updatetime' => date('Y-m-d H:i:s',time())
		]);
		  
		return $data;
    }
	
	public static function updOneReturnorder($all)
    {
		$data=Db::name('Returnorder')-> where('id',$all['id'])->update([
			'multipic' => $all['multipic'],
			'Returnordername' => $all['Returnordername'],
			'Returnorderby' => $all['Returnorderby'],
			'catid' => $all['catid'],
			'isshow' => $all['catid'],
			'stock' => $all['stock'],
			'price' => $all['price'],
			'superreward' => $all['superreward'],
			'bigreward' => $all['bigreward'],
			'agentprice' => $all['agentprice'],
			'detail' => $all['detail'],
			'updatetime' => date('Y-m-d H:i:s',time())
		]);
		return $data;
    }
	
	/**
     * @param $where
     * @return array|false|\PDOStatement|string|\think\Model
     * 查询详情
     */
    public static function getListByWhere($where, $page = 0, $pageSize = 10){
		$pageSize = $pageSize <= 0 ? 10 : $pageSize;
        $list = Db::name('Returnorder')->where($where)->limit($page, $pageSize)->order('id DESC')->select();
		foreach($list as $k=>$v){
			if($v['status']==1){
				$list[$k]['status']="审核通过";
			}elseif($v['status']==2){
				$list[$k]['status']="待审核";
			}elseif($v['status']==3){
				$list[$k]['status']="审核未通过";
			}
		}
		return $list;
    }
	
	public static function getCount($where = ''){
        return model("Returnorder")->where($where)->count();
    } 
	
}